home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / var / lib / python-support / python2.6 / gdata / calendar / service.pyc (.txt) < prev   
Encoding:
Python Compiled Bytecode  |  2009-04-20  |  26.1 KB  |  537 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. '''CalendarService extends the GDataService to streamline Google Calendar operations.
  5.  
  6.   CalendarService: Provides methods to query feeds and manipulate items. Extends 
  7.                 GDataService.
  8.  
  9.   DictionaryToParamList: Function which converts a dictionary into a list of 
  10.                          URL arguments (represented as strings). This is a 
  11.                          utility function used in CRUD operations.
  12. '''
  13. __author__ = 'api.vli (Vivian Li)'
  14. import urllib
  15. import gdata
  16. import atom.service as atom
  17. import gdata.service as gdata
  18. import gdata.calendar as gdata
  19. import atom
  20. DEFAULT_BATCH_URL = 'http://www.google.com/calendar/feeds/default/private/full/batch'
  21.  
  22. class Error(Exception):
  23.     pass
  24.  
  25.  
  26. class RequestError(Error):
  27.     pass
  28.  
  29.  
  30. class CalendarService(gdata.service.GDataService):
  31.     '''Client for the Google Calendar service.'''
  32.     
  33.     def __init__(self, email = None, password = None, source = None, server = 'www.google.com', additional_headers = None, **kwargs):
  34.         """Creates a client for the Google Calendar service.
  35.  
  36.     Args:
  37.       email: string (optional) The user's email address, used for
  38.           authentication.
  39.       password: string (optional) The user's password.
  40.       source: string (optional) The name of the user's application.
  41.       server: string (optional) The name of the server to which a connection
  42.           will be opened. Default value: 'www.google.com'.
  43.       **kwargs: The other parameters to pass to gdata.service.GDataService
  44.           constructor.
  45.     """
  46.         gdata.service.GDataService.__init__(self, email = email, password = password, service = 'cl', source = source, server = server, additional_headers = additional_headers, **kwargs)
  47.  
  48.     
  49.     def GetCalendarEventFeed(self, uri = '/calendar/feeds/default/private/full'):
  50.         return self.Get(uri, converter = gdata.calendar.CalendarEventFeedFromString)
  51.  
  52.     
  53.     def GetCalendarEventEntry(self, uri):
  54.         return self.Get(uri, converter = gdata.calendar.CalendarEventEntryFromString)
  55.  
  56.     
  57.     def GetCalendarListFeed(self, uri = '/calendar/feeds/default/allcalendars/full'):
  58.         return self.Get(uri, converter = gdata.calendar.CalendarListFeedFromString)
  59.  
  60.     
  61.     def GetAllCalendarsFeed(self, uri = '/calendar/feeds/default/allcalendars/full'):
  62.         return self.Get(uri, converter = gdata.calendar.CalendarListFeedFromString)
  63.  
  64.     
  65.     def GetOwnCalendarsFeed(self, uri = '/calendar/feeds/default/owncalendars/full'):
  66.         return self.Get(uri, converter = gdata.calendar.CalendarListFeedFromString)
  67.  
  68.     
  69.     def GetCalendarListEntry(self, uri):
  70.         return self.Get(uri, converter = gdata.calendar.CalendarListEntryFromString)
  71.  
  72.     
  73.     def GetCalendarAclFeed(self, uri = '/calendar/feeds/default/acl/full'):
  74.         return self.Get(uri, converter = gdata.calendar.CalendarAclFeedFromString)
  75.  
  76.     
  77.     def GetCalendarAclEntry(self, uri):
  78.         return self.Get(uri, converter = gdata.calendar.CalendarAclEntryFromString)
  79.  
  80.     
  81.     def GetCalendarEventCommentFeed(self, uri):
  82.         return self.Get(uri, converter = gdata.calendar.CalendarEventCommentFeedFromString)
  83.  
  84.     
  85.     def GetCalendarEventCommentEntry(self, uri):
  86.         return self.Get(uri, converter = gdata.calendar.CalendarEventCommentEntryFromString)
  87.  
  88.     
  89.     def Query(self, uri, converter = None):
  90.         """Performs a query and returns a resulting feed or entry.
  91.  
  92.     Args:
  93.       feed: string The feed which is to be queried
  94.  
  95.     Returns:
  96.       On success, a GDataFeed or Entry depending on which is sent from the 
  97.         server.
  98.       On failure, a RequestError is raised of the form:
  99.         {'status': HTTP status code from server, 
  100.          'reason': HTTP reason from the server, 
  101.          'body': HTTP body of the server's response}
  102.     """
  103.         if converter:
  104.             result = self.Get(uri, converter = converter)
  105.         else:
  106.             result = self.Get(uri)
  107.         return result
  108.  
  109.     
  110.     def CalendarQuery(self, query):
  111.         if isinstance(query, CalendarEventQuery):
  112.             return self.Query(query.ToUri(), converter = gdata.calendar.CalendarEventFeedFromString)
  113.         if isinstance(query, CalendarListQuery):
  114.             return self.Query(query.ToUri(), converter = gdata.calendar.CalendarListFeedFromString)
  115.         if isinstance(query, CalendarEventCommentQuery):
  116.             return self.Query(query.ToUri(), converter = gdata.calendar.CalendarEventCommentFeedFromString)
  117.         return self.Query(query.ToUri())
  118.  
  119.     
  120.     def InsertEvent(self, new_event, insert_uri, url_params = None, escape_params = True):
  121.         """Adds an event to Google Calendar.
  122.  
  123.     Args: 
  124.       new_event: atom.Entry or subclass A new event which is to be added to 
  125.                 Google Calendar.
  126.       insert_uri: the URL to post new events to the feed
  127.       url_params: dict (optional) Additional URL parameters to be included
  128.                   in the insertion request. 
  129.       escape_params: boolean (optional) If true, the url_parameters will be
  130.                      escaped before they are included in the request.
  131.  
  132.     Returns:
  133.       On successful insert,  an entry containing the event created
  134.       On failure, a RequestError is raised of the form:
  135.         {'status': HTTP status code from server, 
  136.          'reason': HTTP reason from the server, 
  137.          'body': HTTP body of the server's response}
  138.     """
  139.         return self.Post(new_event, insert_uri, url_params = url_params, escape_params = escape_params, converter = gdata.calendar.CalendarEventEntryFromString)
  140.  
  141.     
  142.     def InsertCalendarSubscription(self, calendar, url_params = None, escape_params = True):
  143.         """Subscribes the authenticated user to the provided calendar.
  144.     
  145.     Args: 
  146.       calendar: The calendar to which the user should be subscribed.
  147.       url_params: dict (optional) Additional URL parameters to be included
  148.                   in the insertion request. 
  149.       escape_params: boolean (optional) If true, the url_parameters will be
  150.                      escaped before they are included in the request.
  151.  
  152.     Returns:
  153.       On successful insert,  an entry containing the subscription created
  154.       On failure, a RequestError is raised of the form:
  155.         {'status': HTTP status code from server, 
  156.          'reason': HTTP reason from the server, 
  157.          'body': HTTP body of the server's response}
  158.     """
  159.         insert_uri = '/calendar/feeds/default/allcalendars/full'
  160.         return self.Post(calendar, insert_uri, url_params = url_params, escape_params = escape_params, converter = gdata.calendar.CalendarListEntryFromString)
  161.  
  162.     
  163.     def InsertCalendar(self, new_calendar, url_params = None, escape_params = True):
  164.         """Creates a new calendar.
  165.     
  166.     Args: 
  167.       new_calendar: The calendar to be created
  168.       url_params: dict (optional) Additional URL parameters to be included
  169.                   in the insertion request. 
  170.       escape_params: boolean (optional) If true, the url_parameters will be
  171.                      escaped before they are included in the request.
  172.  
  173.     Returns:
  174.       On successful insert,  an entry containing the calendar created
  175.       On failure, a RequestError is raised of the form:
  176.         {'status': HTTP status code from server, 
  177.          'reason': HTTP reason from the server, 
  178.          'body': HTTP body of the server's response}
  179.     """
  180.         insert_uri = '/calendar/feeds/default/owncalendars/full'
  181.         response = self.Post(new_calendar, insert_uri, url_params = url_params, escape_params = escape_params, converter = gdata.calendar.CalendarListEntryFromString)
  182.         return response
  183.  
  184.     
  185.     def UpdateCalendar(self, calendar, url_params = None, escape_params = True):
  186.         """Updates a calendar.
  187.     
  188.     Args: 
  189.       calendar: The calendar which should be updated
  190.       url_params: dict (optional) Additional URL parameters to be included
  191.                   in the insertion request. 
  192.       escape_params: boolean (optional) If true, the url_parameters will be
  193.                      escaped before they are included in the request.
  194.  
  195.     Returns:
  196.       On successful insert,  an entry containing the calendar created
  197.       On failure, a RequestError is raised of the form:
  198.         {'status': HTTP status code from server, 
  199.          'reason': HTTP reason from the server, 
  200.          'body': HTTP body of the server's response}
  201.     """
  202.         update_uri = calendar.GetEditLink().href
  203.         response = self.Put(data = calendar, uri = update_uri, url_params = url_params, escape_params = escape_params, converter = gdata.calendar.CalendarListEntryFromString)
  204.         return response
  205.  
  206.     
  207.     def InsertAclEntry(self, new_entry, insert_uri, url_params = None, escape_params = True):
  208.         """Adds an ACL entry (rule) to Google Calendar.
  209.  
  210.     Args: 
  211.       new_entry: atom.Entry or subclass A new ACL entry which is to be added to 
  212.                 Google Calendar.
  213.       insert_uri: the URL to post new entries to the ACL feed
  214.       url_params: dict (optional) Additional URL parameters to be included
  215.                   in the insertion request. 
  216.       escape_params: boolean (optional) If true, the url_parameters will be
  217.                      escaped before they are included in the request.
  218.  
  219.     Returns:
  220.       On successful insert,  an entry containing the ACL entry created
  221.       On failure, a RequestError is raised of the form:
  222.         {'status': HTTP status code from server, 
  223.          'reason': HTTP reason from the server, 
  224.          'body': HTTP body of the server's response}
  225.     """
  226.         return self.Post(new_entry, insert_uri, url_params = url_params, escape_params = escape_params, converter = gdata.calendar.CalendarAclEntryFromString)
  227.  
  228.     
  229.     def InsertEventComment(self, new_entry, insert_uri, url_params = None, escape_params = True):
  230.         """Adds an entry to Google Calendar.
  231.  
  232.     Args:
  233.       new_entry: atom.Entry or subclass A new entry which is to be added to
  234.                 Google Calendar.
  235.       insert_uri: the URL to post new entrys to the feed
  236.       url_params: dict (optional) Additional URL parameters to be included
  237.                   in the insertion request.
  238.       escape_params: boolean (optional) If true, the url_parameters will be
  239.                      escaped before they are included in the request.
  240.  
  241.     Returns:
  242.       On successful insert,  an entry containing the comment created
  243.       On failure, a RequestError is raised of the form:
  244.         {'status': HTTP status code from server, 
  245.          'reason': HTTP reason from the server, 
  246.          'body': HTTP body of the server's response}
  247.     """
  248.         return self.Post(new_entry, insert_uri, url_params = url_params, escape_params = escape_params, converter = gdata.calendar.CalendarEventCommentEntryFromString)
  249.  
  250.     
  251.     def DeleteEvent(self, edit_uri, extra_headers = None, url_params = None, escape_params = True):
  252.         """Removes an event with the specified ID from Google Calendar.
  253.  
  254.     Args:
  255.       edit_uri: string The edit URL of the entry to be deleted. Example:
  256.                'http://www.google.com/calendar/feeds/default/private/full/abx'
  257.       url_params: dict (optional) Additional URL parameters to be included
  258.                   in the deletion request.
  259.       escape_params: boolean (optional) If true, the url_parameters will be
  260.                      escaped before they are included in the request.
  261.  
  262.     Returns:
  263.       On successful delete,  a httplib.HTTPResponse containing the server's
  264.         response to the DELETE request.
  265.       On failure, a RequestError is raised of the form:
  266.         {'status': HTTP status code from server, 
  267.          'reason': HTTP reason from the server, 
  268.          'body': HTTP body of the server's response}
  269.     """
  270.         url_prefix = 'http://%s/' % self.server
  271.         if edit_uri.startswith(url_prefix):
  272.             edit_uri = edit_uri[len(url_prefix):]
  273.         
  274.         return self.Delete('/%s' % edit_uri, url_params = url_params, escape_params = escape_params)
  275.  
  276.     
  277.     def DeleteAclEntry(self, edit_uri, extra_headers = None, url_params = None, escape_params = True):
  278.         """Removes an ACL entry at the given edit_uri from Google Calendar.
  279.  
  280.     Args:
  281.       edit_uri: string The edit URL of the entry to be deleted. Example:
  282.                'http://www.google.com/calendar/feeds/liz%40gmail.com/acl/full/default'
  283.       url_params: dict (optional) Additional URL parameters to be included
  284.                   in the deletion request.
  285.       escape_params: boolean (optional) If true, the url_parameters will be
  286.                      escaped before they are included in the request.
  287.  
  288.     Returns:
  289.       On successful delete,  a httplib.HTTPResponse containing the server's
  290.         response to the DELETE request.
  291.       On failure, a RequestError is raised of the form:
  292.         {'status': HTTP status code from server, 
  293.          'reason': HTTP reason from the server, 
  294.          'body': HTTP body of the server's response}
  295.     """
  296.         url_prefix = 'http://%s/' % self.server
  297.         if edit_uri.startswith(url_prefix):
  298.             edit_uri = edit_uri[len(url_prefix):]
  299.         
  300.         return self.Delete('/%s' % edit_uri, url_params = url_params, escape_params = escape_params)
  301.  
  302.     
  303.     def DeleteCalendarEntry(self, edit_uri, extra_headers = None, url_params = None, escape_params = True):
  304.         """Removes a calendar entry at the given edit_uri from Google Calendar.
  305.  
  306.     Args:
  307.       edit_uri: string The edit URL of the entry to be deleted. Example:
  308.                'http://www.google.com/calendar/feeds/default/allcalendars/abcdef@group.calendar.google.com'
  309.       url_params: dict (optional) Additional URL parameters to be included
  310.                   in the deletion request.
  311.       escape_params: boolean (optional) If true, the url_parameters will be
  312.                      escaped before they are included in the request.
  313.  
  314.     Returns:
  315.       On successful delete, True is returned
  316.       On failure, a RequestError is raised of the form:
  317.         {'status': HTTP status code from server, 
  318.          'reason': HTTP reason from the server, 
  319.          'body': HTTP body of the server's response}
  320.     """
  321.         return self.Delete(edit_uri, url_params = url_params, escape_params = escape_params)
  322.  
  323.     
  324.     def UpdateEvent(self, edit_uri, updated_event, url_params = None, escape_params = True):
  325.         """Updates an existing event.
  326.  
  327.     Args:
  328.       edit_uri: string The edit link URI for the element being updated
  329.       updated_event: string, atom.Entry, or subclass containing
  330.                     the Atom Entry which will replace the event which is 
  331.                     stored at the edit_url 
  332.       url_params: dict (optional) Additional URL parameters to be included
  333.                   in the update request.
  334.       escape_params: boolean (optional) If true, the url_parameters will be
  335.                      escaped before they are included in the request.
  336.  
  337.     Returns:
  338.       On successful update,  a httplib.HTTPResponse containing the server's
  339.         response to the PUT request.
  340.       On failure, a RequestError is raised of the form:
  341.         {'status': HTTP status code from server, 
  342.          'reason': HTTP reason from the server, 
  343.          'body': HTTP body of the server's response}
  344.     """
  345.         url_prefix = 'http://%s/' % self.server
  346.         if edit_uri.startswith(url_prefix):
  347.             edit_uri = edit_uri[len(url_prefix):]
  348.         
  349.         return self.Put(updated_event, '/%s' % edit_uri, url_params = url_params, escape_params = escape_params, converter = gdata.calendar.CalendarEventEntryFromString)
  350.  
  351.     
  352.     def UpdateAclEntry(self, edit_uri, updated_rule, url_params = None, escape_params = True):
  353.         """Updates an existing ACL rule.
  354.  
  355.     Args:
  356.       edit_uri: string The edit link URI for the element being updated
  357.       updated_rule: string, atom.Entry, or subclass containing
  358.                     the Atom Entry which will replace the event which is 
  359.                     stored at the edit_url 
  360.       url_params: dict (optional) Additional URL parameters to be included
  361.                   in the update request.
  362.       escape_params: boolean (optional) If true, the url_parameters will be
  363.                      escaped before they are included in the request.
  364.  
  365.     Returns:
  366.       On successful update,  a httplib.HTTPResponse containing the server's
  367.         response to the PUT request.
  368.       On failure, a RequestError is raised of the form:
  369.         {'status': HTTP status code from server, 
  370.          'reason': HTTP reason from the server, 
  371.          'body': HTTP body of the server's response}
  372.     """
  373.         url_prefix = 'http://%s/' % self.server
  374.         if edit_uri.startswith(url_prefix):
  375.             edit_uri = edit_uri[len(url_prefix):]
  376.         
  377.         return self.Put(updated_rule, '/%s' % edit_uri, url_params = url_params, escape_params = escape_params, converter = gdata.calendar.CalendarAclEntryFromString)
  378.  
  379.     
  380.     def ExecuteBatch(self, batch_feed, url, converter = gdata.calendar.CalendarEventFeedFromString):
  381.         """Sends a batch request feed to the server.
  382.  
  383.     The batch request needs to be sent to the batch URL for a particular 
  384.     calendar. You can find the URL by calling GetBatchLink().href on the 
  385.     CalendarEventFeed.
  386.  
  387.     Args:
  388.       batch_feed: gdata.calendar.CalendarEventFeed A feed containing batch
  389.           request entries. Each entry contains the operation to be performed 
  390.           on the data contained in the entry. For example an entry with an 
  391.           operation type of insert will be used as if the individual entry 
  392.           had been inserted.
  393.       url: str The batch URL for the Calendar to which these operations should
  394.           be applied.
  395.       converter: Function (optional) The function used to convert the server's
  396.           response to an object. The default value is 
  397.           CalendarEventFeedFromString.
  398.      
  399.     Returns:
  400.       The results of the batch request's execution on the server. If the 
  401.       default converter is used, this is stored in a CalendarEventFeed.
  402.     """
  403.         return self.Post(batch_feed, url, converter = converter)
  404.  
  405.  
  406.  
  407. class CalendarEventQuery(gdata.service.Query):
  408.     
  409.     def __init__(self, user = 'default', visibility = 'private', projection = 'full', text_query = None, params = None, categories = None):
  410.         gdata.service.Query.__init__(self, feed = 'http://www.google.com/calendar/feeds/%s/%s/%s' % (urllib.quote(user), urllib.quote(visibility), urllib.quote(projection)), text_query = text_query, params = params, categories = categories)
  411.  
  412.     
  413.     def _GetStartMin(self):
  414.         if 'start-min' in self.keys():
  415.             return self['start-min']
  416.         return None
  417.  
  418.     
  419.     def _SetStartMin(self, val):
  420.         self['start-min'] = val
  421.  
  422.     start_min = property(_GetStartMin, _SetStartMin, doc = 'The start-min query parameter')
  423.     
  424.     def _GetStartMax(self):
  425.         if 'start-max' in self.keys():
  426.             return self['start-max']
  427.         return None
  428.  
  429.     
  430.     def _SetStartMax(self, val):
  431.         self['start-max'] = val
  432.  
  433.     start_max = property(_GetStartMax, _SetStartMax, doc = 'The start-max query parameter')
  434.     
  435.     def _GetOrderBy(self):
  436.         if 'orderby' in self.keys():
  437.             return self['orderby']
  438.         return None
  439.  
  440.     
  441.     def _SetOrderBy(self, val):
  442.         if val is not 'lastmodified' and val is not 'starttime':
  443.             raise Error, "Order By must be either 'lastmodified' or 'starttime'"
  444.         val is not 'starttime'
  445.         self['orderby'] = val
  446.  
  447.     orderby = property(_GetOrderBy, _SetOrderBy, doc = 'The orderby query parameter')
  448.     
  449.     def _GetSortOrder(self):
  450.         if 'sortorder' in self.keys():
  451.             return self['sortorder']
  452.         return None
  453.  
  454.     
  455.     def _SetSortOrder(self, val):
  456.         if val is not 'ascending' and val is not 'descending' and val is not 'a' and val is not 'd' and val is not 'ascend' and val is not 'descend':
  457.             raise Error, 'Sort order must be either ascending, ascend, ' + 'a or descending, descend, or d'
  458.         val is not 'descend'
  459.         self['sortorder'] = val
  460.  
  461.     sortorder = property(_GetSortOrder, _SetSortOrder, doc = 'The sortorder query parameter')
  462.     
  463.     def _GetSingleEvents(self):
  464.         if 'singleevents' in self.keys():
  465.             return self['singleevents']
  466.         return None
  467.  
  468.     
  469.     def _SetSingleEvents(self, val):
  470.         self['singleevents'] = val
  471.  
  472.     singleevents = property(_GetSingleEvents, _SetSingleEvents, doc = 'The singleevents query parameter')
  473.     
  474.     def _GetFutureEvents(self):
  475.         if 'futureevents' in self.keys():
  476.             return self['futureevents']
  477.         return None
  478.  
  479.     
  480.     def _SetFutureEvents(self, val):
  481.         self['futureevents'] = val
  482.  
  483.     futureevents = property(_GetFutureEvents, _SetFutureEvents, doc = 'The futureevents query parameter')
  484.     
  485.     def _GetRecurrenceExpansionStart(self):
  486.         if 'recurrence-expansion-start' in self.keys():
  487.             return self['recurrence-expansion-start']
  488.         return None
  489.  
  490.     
  491.     def _SetRecurrenceExpansionStart(self, val):
  492.         self['recurrence-expansion-start'] = val
  493.  
  494.     recurrence_expansion_start = property(_GetRecurrenceExpansionStart, _SetRecurrenceExpansionStart, doc = 'The recurrence-expansion-start query parameter')
  495.     
  496.     def _GetRecurrenceExpansionEnd(self):
  497.         if 'recurrence-expansion-end' in self.keys():
  498.             return self['recurrence-expansion-end']
  499.         return None
  500.  
  501.     
  502.     def _SetRecurrenceExpansionEnd(self, val):
  503.         self['recurrence-expansion-end'] = val
  504.  
  505.     recurrence_expansion_end = property(_GetRecurrenceExpansionEnd, _SetRecurrenceExpansionEnd, doc = 'The recurrence-expansion-end query parameter')
  506.     
  507.     def _SetTimezone(self, val):
  508.         self['ctz'] = val
  509.  
  510.     
  511.     def _GetTimezone(self):
  512.         if 'ctz' in self.keys():
  513.             return self['ctz']
  514.         return None
  515.  
  516.     ctz = property(_GetTimezone, _SetTimezone, doc = 'The ctz query parameter which sets report time on the server.')
  517.  
  518.  
  519. class CalendarListQuery(gdata.service.Query):
  520.     '''Queries the Google Calendar meta feed'''
  521.     
  522.     def __init__(self, userId = None, text_query = None, params = None, categories = None):
  523.         if userId is None:
  524.             userId = 'default'
  525.         
  526.         gdata.service.Query.__init__(self, feed = 'http://www.google.com/calendar/feeds/' + userId, text_query = text_query, params = params, categories = categories)
  527.  
  528.  
  529.  
  530. class CalendarEventCommentQuery(gdata.service.Query):
  531.     '''Queries the Google Calendar event comments feed'''
  532.     
  533.     def __init__(self, feed = None):
  534.         gdata.service.Query.__init__(self, feed = feed)
  535.  
  536.  
  537.